package cn.monkey.family.server.domain.uc.auth.session;

import cn.monkey.family.data.uc.auth.UserSession;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;

public class CacheableUserSessionRepository implements UserSessionRepository {
    private final Cache cache;

    public CacheableUserSessionRepository(CacheManager cacheManager) {
        this.cache = cacheManager.getCache(UserSession.KEY);
    }

    @Override
    public void save(UserSession userSession) {
        this.cache.put(userSession.getUid(), userSession);
    }

    @Override
    public UserSession find(String uid) {
        return this.cache.get(uid, UserSession.class);
    }

    @Override
    public void delete(String uid) {
        this.cache.put(uid, null);
    }
}
